from django.db import models
from dingxiang.utils.models import BaseModel

# Create your models here.

# 药物方向
class MedicineDirectionModel(models.Model):
    direction = models.CharField(max_length=255, verbose_name="药物方向")

    class Meta:
        db_table = 'medicine_direction'
        verbose_name_plural = '药物方向'

    def __str__(self):
        return self.direction

# 药物分类
class MedicineClassificationModel(models.Model):
    classification = models.CharField(max_length=255, verbose_name="药物分类")
    recomment_home = models.BooleanField(default=False,verbose_name='是否推荐首页栏目')
    medicine_direction = models.OneToOneField(MedicineDirectionModel, on_delete=models.CASCADE, verbose_name='药物方向')
    class Meta:
        db_table = 'medicine_classification'
        verbose_name_plural = '药物分类'

    def __str__(self):
        return self.classification

# 药物
class MedicineModel(models.Model):
    name = models.CharField(max_length=255, verbose_name="药物名称")
    content = models.TextField(verbose_name="内容")
    medicine_image = models.ImageField(upload_to='medicine/', verbose_name="药物图片")
    bibliography = models.TextField(blank=True, null=True, verbose_name="参考文献")
    external_links = models.URLField(max_length=255, blank=True, null=True, verbose_name="外部链接")
    medicine_classification = models.OneToOneField(MedicineClassificationModel, on_delete=models.CASCADE, verbose_name='药物分类')
    class Meta:
        db_table = 'medicine'
        verbose_name_plural = '药物'

    def __str__(self):
        return self.name

# 药物内容
class MedicineContentModel(models.Model):
    content = models.TextField(verbose_name="药物内容")
    medicine = models.OneToOneField(MedicineModel, on_delete=models.CASCADE, verbose_name="药物")

    class Meta:
        db_table = 'medicine_content'
        verbose_name_plural = '药物内容'

    def __str__(self):
        return f"Content for {self.medicine.name}"
